﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using SBS_Map_Editor.MapClasses;

namespace SBS_Map_Editor
{
    public partial class Form1 : Form
    {
        #region Variables
        Map map;
        #endregion

        public Form1()
        {
            InitializeComponent();
        }

        private void mousePosition_MouseMove(object sender, MouseEventArgs e)
        {
            mousePosition.Text = e.Location.ToString();
        }

        private void New_Click(object sender, EventArgs e)
        {
            map = new Map();
        }

        private void Open_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            // Default to the directory which contains our content files.
            string assemblyLocation = Assembly.GetExecutingAssembly().Location;
            string relativePath = Path.Combine(assemblyLocation, "../../../../data");
            string contentPath = Path.GetFullPath(relativePath);
            map.Path = contentPath;

            open.InitialDirectory = map.Path;

            open.Title = "Load Map";

            open.Filter = "Content Files (*.THMM;*.THM)|*.THM;*.THM|" +
                                "Hannitizer Map Files (*.THM)|*.THM|" + "All Files (*.*)|*.*";

            if (open.ShowDialog() == DialogResult.OK)
            {
                map.Read();
            }
        }

        private void Save_Click(object sender, EventArgs e)
        {
            SaveFileDialog save = new SaveFileDialog();
            // Default to the directory which contains our content files.
            string assemblyLocation = Assembly.GetExecutingAssembly().Location;
            string relativePath = Path.Combine(assemblyLocation, "../../../../data");
            string contentPath = Path.GetFullPath(relativePath);
            map.Path = contentPath;

            save.InitialDirectory = map.Path;
            save.Title = "Save Map";
            save.Filter = "Content Files (*.THMM;*.THM)|*.THM;*.THM|" +
                                "Hannitizer Map Files (*.THM)|*.THM|" + "All Files (*.*)|*.*";

            if (save.ShowDialog()==DialogResult.OK)
            {
                map.Write();
            }
        }
    }
}